using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xml;
using ICSharpCode.TextEditor.Document;

namespace ICSharpCode.TextEditor.Src.Document.HighlightingStrategy.SyntaxModes
{
	public class ResourceSyntaxModeProviderEx : ISyntaxModeFileProvider
	{
		private const string ResourcesDir = "ICSharpCode.TextEditor.Resources.";

		private readonly List<SyntaxMode> _syntaxModes;

		public ICollection<SyntaxMode> SyntaxModes => this._syntaxModes;

		public ResourceSyntaxModeProviderEx()
		{
			Stream syntaxModeStream = this.GetSyntaxModeStream("SyntaxModesEx.xml");
			this._syntaxModes = ((syntaxModeStream != null) ? SyntaxMode.GetSyntaxModes(syntaxModeStream) : new List<SyntaxMode>());
		}

		public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
		{
			Stream syntaxModeStream = this.GetSyntaxModeStream(syntaxMode.FileName);
			return (syntaxModeStream != null) ? new XmlTextReader(syntaxModeStream) : null;
		}

		public void UpdateSyntaxModeList()
		{
		}

		private Stream GetSyntaxModeStream(string filename)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			return executingAssembly.GetManifestResourceStream(string.Format("{0}{1}", "ICSharpCode.TextEditor.Resources.", filename));
		}
	}
}
